//
//  FWAuthViewController.m
//  FWShare
//
//  Created by 范文青 on 14-6-14.
//  Copyright (c) 2014年 fwq. All rights reserved.
//

#import "FWAuthViewController.h"
#import "FWSinaAuthHandler.h"
#import "FWShareValues.h"
#import "FWQQHuLianAuthHandler.h"
#import "FWQQWeiBoAuthHandler.h"
#import "FWAuthUser.h"
@interface FWAuthViewController ()<UIWebViewDelegate>
{
    
}
@property (nonatomic,strong)FWAuthHandler *authHandler;
@property (nonatomic,strong)NSString   *platform;
@end


@implementation FWAuthViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}
- (instancetype)initWithPlatform:(NSString *)platform
{
    self = [super init];
    if (self) {
        self.platform = platform;
    }
    return self;
}
- (void)setPlatform:(NSString *)platform
{
    _platform = platform;
    if ([platform isEqualToString:SINA_WEIBO]) {
        self.authHandler = [FWSinaAuthHandler new];
    }else if ([platform isEqualToString:QQ_HULIAN]) {
        self.authHandler = [FWQQHuLianAuthHandler new];
    }else if ([platform isEqualToString:QQ_WEIBO]){
        self.authHandler = [FWQQWeiBoAuthHandler new];
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    
    _authWebView = [[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [_authWebView setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
    [_authWebView setScalesPageToFit:YES];
    [self.view addSubview:_authWebView];
    
    [self.view setBackgroundColor:[UIColor blackColor]];
//    if (IOS7UPPER) {
//        [self setNeedsStatusBarAppearanceUpdate];
//    }
    
}

- (void)back:(id)sender{
    if (_authCanceled) {
        _authCanceled(_platform);
    }
}

- (void)auth
{
    [self.authHandler setForceAuth:_forceAuth];
    if (!_forceAuth) {
        FWAuthUser  *user = [FWAuthUser userByMediaType:_platform];
        if (user != nil) {
            _authSuccess(user,_platform);
            return;
        }
    }
    [self.authHandler startAuth:self];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}
//- (UIStatusBarStyle)preferredStatusBarStyle
//{
//    return UIStatusBarStyleLightContent;
//}


@end
